#pragma once

typedef struct _IDTE 
{
    UINT16  Offset0To15;
    UINT16  Selector;
    UINT8   Flags;
    UINT8   Access;
    UINT16  Offset16To31;
    UINT32  Offset32To63;
    UINT32  Reserved;
} IDTE, *PIDTE;

#define GDTE_ACCESSED		0x1 
#define GDTE_CallGate16		0x4 
#define GDTE_CallGate32		0xc 
#define GDTE_CODE			0x8 
#define GDTE_CONFORMING		0x4 
#define GDTE_EXPANDDOWN		0x4 
#define GDTE_IntGate16		0x6 
#define GDTE_IntGate32		0xe 
#define GDTE_IS32BIT		0x40 
#define GDTE_IS64BIT		0x20 
#define GDTE_Ldt			0x2 
#define GDTE_LIMIT20		0xf 
#define GDTE_PAGES			0x80 
#define GDTE_PRESENT		0x80 
#define GDTE_READABLE		0x2 
#define GDTE_Reserved10		0xa 
#define GDTE_Reserved13		0xd 
#define GDTE_Reserved8		0x8 
#define GDTE_RING0			0x0 
#define GDTE_RING1			0x20 
#define GDTE_RING2			0x40 
#define GDTE_RING3			0x60 
#define GDTE_TaskGate		0x5 
#define GDTE_TrapGate16		0x7 
#define GDTE_TrapGate32		0xf 
#define GDTE_Tss16Busy		0x3 
#define GDTE_Tss16Free		0x1 
#define GDTE_Tss32Busy		0xb 
#define GDTE_Tss32Free		0x9 
#define GDTE_USER			0x10 
#define GDTE_WRITEABLE		0x2 

typedef struct _GDTE
{
  UINT16 limit; 
  UINT16 base0_15;
  UINT8 base16_23;
  UINT8 access; 
  UINT8 granularity;
  UINT8 base24_31;
} GDTE;

typedef struct _GDT
{
  GDTE nul;
  GDTE pv; 
  GDTE rc; 
  GDTE rd; 
  GDTE pc; 
  GDTE pd; 
  GDTE lc; 
  GDTE ld; 
  GDTE uc; 
  GDTE ud; 
  GDTE pp; 
  GDTE nn; 
  GDTE tss; 
} GDT;

typedef struct _DESCR_TABLE
{
  GDT gdt; 
  GDTR gdtPtr;
} DESCR_TABLE;

typedef struct _TSS
{
  UINT64 reserved1;
  UINT64 rsp0;
  UINT64 rsp1;
  UINT64 rsp3;

  UINT64 reserved2;

  UINT64 ist1;
  UINT64 ist2;
  UINT64 ist3;
  UINT64 ist4;
  UINT64 ist5;
  UINT64 ist6;
  UINT64 ist7;

  UINT64 reserved3;
  UINT32 reserved4;
  UINT32 io_bitmap_offset;
} TSS;
